﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmEditDCInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected int intID = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLIsAllLook;
        protected RadioButtonList RBLIsAnony;
        protected RadioButtonList RBLIsIP;
        protected string strReUserCode = "所有人员";
        protected string strReUserName = "所有人员";
        protected TextBox txtEndDate;
        protected TextBox txtTitleInfo;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            string str2 = "";
            str = "," + base.Request.Form["txtBrowUserCode"].ToString() + ",";
            str2 = "," + base.Request.Form["txtBrowUserName"].ToString() + ",";
            string strSql = "";
            if (this.intID == 0)
            {
                strSql = "Insert Into OnlineQuest(EndTime,DCUserCode,DCUserName,IsAnyUser,IsLook,IsIP,CreatUser,Status,TitleInfo) values(";
                strSql = strSql + "'" + this.txtEndDate.Text.Trim() + "','" + str + "','" + str2 + "','" + this.RBLIsAnony.SelectedItem.Value + "','" + this.RBLIsAllLook.SelectedItem.Value + "',";
                strSql = strSql + "'" + this.RBLIsIP.SelectedItem.Value + "','" + this.httpCookie_1.Value + "','A','" + this.publicFun_0.CheckString(this.txtTitleInfo.Text) + "')";
                strSql = strSql + "insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('新增[" + this.publicFun_0.CheckString(this.txtTitleInfo.Text) + "]在线调查信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')";
                this.publicFun_0.RetrunExecute(strSql);
            }
            else
            {
                strSql = "update OnlineQuest set TitleInfo='" + this.publicFun_0.CheckString(this.txtTitleInfo.Text) + "',IsIP='" + this.RBLIsIP.SelectedItem.Value + "',IsAnyUser='" + this.RBLIsAnony.SelectedItem.Value + "',";
                strSql = strSql + "IsLook='" + this.RBLIsAllLook.SelectedItem.Value + "',EndTime='" + this.txtEndDate.Text.Trim() + "',Status='A',DCUserCode='" + str + "',";
                strSql = string.Concat(new object[] { strSql, "DCUserName='", str2, "',CreatUser='", this.httpCookie_1.Value, "' where Status='A' and  ID=", this.intID });
                strSql = strSql + "insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('编辑[" + this.publicFun_0.CheckString(this.txtTitleInfo.Text) + "]在线调查信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')";
                this.publicFun_0.ExecuteSql(strSql);
            }
            base.Response.Write("<script>alert('提交在线调查操作成功！');window.opener.location.href='ManagDCList.aspx';window.close();</script>");
        }

        private void method_0()
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlDataReader reader = new SqlCommand("select ID,TitleInfo,EndTime,DCUserCode,DCUserName,IsAnyUser,IsLook,IsIP,CreatUser,CreatTime,Status from OnlineQuest where Status='A' and ID=" + this.intID, connection).ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.RBLIsIP.SelectedIndex = -1;
                this.RBLIsAnony.SelectedIndex = -1;
                this.RBLIsAllLook.SelectedIndex = -1;
                this.txtTitleInfo.Text = reader["TitleInfo"].ToString();
                this.RBLIsIP.Items.FindByValue(reader["IsIP"].ToString()).Selected = true;
                this.RBLIsAnony.Items.FindByValue(reader["IsAnyUser"].ToString()).Selected = true;
                this.RBLIsAllLook.Items.FindByValue(reader["IsLook"].ToString()).Selected = true;
                this.txtEndDate.Text = reader["EndTime"].ToString();
                this.strReUserName = reader["DCUserName"].ToString().Substring(1, reader["DCUserName"].ToString().Length - 2);
                this.strReUserCode = reader["DCUserCode"].ToString().Substring(1, reader["DCUserCode"].ToString().Length - 2);
            }
            reader.Close();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.intID = Convert.ToInt32(base.Request["ID"].ToString());
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---编辑在线调查信息";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                    else
                    {
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddPoll,ManagPoll from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddPower"] = reader["AddPoll"].ToString();
                            this.ViewState["ManagPower"] = reader["ManagPoll"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if ((this.ViewState["AddPower"].ToString() == "N") ? !(this.ViewState["ManagPower"].ToString() == "N") : true)
                        {
                            this.butDefault.Visible = true;
                        }
                        else
                        {
                            base.Response.Write("<script>alert('添加或管理在线调查权限未开放！')</script>");
                            this.butDefault.Visible = false;
                        }
                        if (this.intID != 0)
                        {
                            this.method_0();
                        }
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

